package edu.whu.webgis.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import edu.whu.webgis.utils.ImgUtil;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@TableName("posting")
@NoArgsConstructor
public class Posting {
    @TableId(type = IdType.AUTO)
    Integer id;
    String pics;
    String content;
    Integer likes;
    String uid;
    String author;
    String category;
    String title;

    public Posting(VPosting posting) {
        this.setContent(posting.getContent());
        this.setLikes(posting.getLikes());
        this.setUid(posting.getUid());
        this.setAuthor(posting.getAuthor());
        this.setTitle(posting.getTitle());
        StringBuilder pics = new StringBuilder();
        for (String pic: posting.getPics()){
            pics.append(ImgUtil.save(pic)).append(" ");
        }
        this.setPics(pics.toString().trim());
        StringBuilder cates = new StringBuilder();
        for (String cate: posting.getCategory()){
            cates.append(cate).append(" ");
        }
        this.setCategory(cates.toString().trim());
    }
}
